<?php
error_reporting(0);
$test = range(1,5);
$remain = $_POST['remain'];
$benjin = $_POST['benjin'];
$used = $_POST['used'];
$sum = $used;

//var_export($_POST);die;
$url = "http://hq.sinajs.cn/list=";
$gupiao = "";

foreach($test as $v){
    $tmp1 = "k".$v;
    $tmp2 = "v".$v;
    if(empty($_POST[$tmp1]) || empty($_POST[$tmp2]))
        break;
    if(strpos($_POST[$tmp1],"0")===0)
        $gupiao .= "sz{$_POST[$tmp1]}";
    else
        $gupiao .= "sh{$_POST[$tmp1]}";

    $buydata[$_POST[$tmp1]] = $_POST[$tmp2];
    $gupiao.=",";
}
$gupiao = rtrim($gupiao,",");

$url.= $gupiao;

$data = file_get_contents($url);
$data = iconv('GB2312','UTF-8',$data);


$data = explode(";",$data);

foreach($data as $v){
    $v=trim($v);
    if(empty($v))
        continue;
    $v = preg_replace("/[\s\S]*(?=\d{6}\=)/","",$v);
    $v = str_replace("=\"",",",$v);
    $v = trim($v,"\"");
    $v = trim($v);
    $vv = explode(",",$v);
    $sum+= $buydata[$vv[0]] * $vv[4];
    echo $vv[1],":<font color='red'>",$vv[4],"</font>\t".$vv[32],"<br>";
    echo "今开:",$vv[2],"，昨收:",$vv[3],"<br>";
    echo "今高:",$vv[5],"，今低:",$vv[6];
    echo "<br>";
}

echo "目前:{$sum},","原本：$benjin,","used:{$used},","remain:{$remain},","earn:".($sum-$benjin+$remain);








